package oct2013;

public class LongestSubstringWithoutRepeatingCharacters {
	public int lengthOfLongestSubstring(String s) {
		int max = 0;
		int n = s.length();
		int[] cnt = new int[256];
		int j = -1;
		for (int i = 0; i < n; ++i) {
			int ch = s.charAt(i);
			cnt[ch]++;
			while (cnt[ch] > 1) {
				cnt[s.charAt(++j)]--;
			}
			max = Math.max(max, i - j);
		}
		return max;
	}
}
